local point1 = LuaAPI.query_unit("生成点1")
local target = LuaAPI.query_unit("方块喷泉1")
local spawnedCount = 0
local maxSpawnCount = 5
local spawnInterval = 2.0

-- 游戏开始事件
LuaAPI.global_register_trigger_event({ EVENT.GAME_INIT }, function()
    print("test")
    -- 注册定时生成怪物事件
    local timerId = LuaAPI.global_register_trigger_event(
        { EVENT.REPEAT_TIMEOUT, spawnInterval },
        function()
            if spawnedCount >= maxSpawnCount then
                LuaAPI.global_unregister_trigger_event(timerId)
                return
            end
            
            -- 生成怪物
            for i = 1, 5 do
                print("生成怪物"..i)
                local monster = LuaAPI.create_creature(9000510, point1.get_position(),math.Quaternion(0, 0, 0).math.Vector3(0,0,0),nil )
                print(monster)
                -- 设置怪物移动逻辑
                local direction = target.get_position() - monster.get_position()
                monster.force_start_move(direction, 1.0) -- 开始移动
                
                spawnedCount = spawnedCount + 1
                if spawnedCount >= maxSpawnCount then
                    break
                end
            end
        end
    )
end)
